import 'package:dk_flutter_base/dk_core.dart';
import 'package:flutter/cupertino.dart';

// actionSheet
Future<int> showActionSheet(@required BuildContext context,List data, {String title = '', void callBack(int) } ) {
  return showCupertinoModalPopup<int>(context: context, builder:(cxt){
    var actions = <Widget>[];
    for (var i = 0; i < data.length; i++) {
      actions.add(
          CupertinoActionSheetAction(onPressed: (){
            Navigator.pop(cxt,i);
            if (callBack != null) {
              callBack(i);
            }
          }, child: Text(data[i]))
      );
    }
    var dialog =CupertinoActionSheet(
      title: Text(title),
      cancelButton: CupertinoActionSheetAction(onPressed: (){
        Navigator.pop(cxt,0);
      }, child: Text("取消")),
      actions: actions,
    );
    return dialog;
  });
}
